HSI strategy analysis

strategy:

  • Entry conditions

    • At pre-set times (9:15am and 13:45pm), we will make a bet.
    • If the price of that pre-set time is higher than previous day close, it will make a Long position; while if the price of that pre-set time is lower than previous day close, it will make a Put position.
  • Exit conditions

    • If the position is winning 80 points (84 points to be exact), it will trigger a trailing stop when it drawdowns by 40 points from the max winning position.
    • If the position is not winning over 80 points, it will trigger a stop loss exit with a 40 points loss.

Multichart statistics shows that the strategy was rather unstable across the course of time of backtesting. With from 2018 to 2020H1, it is basically flat or even losing, but during 2020H2, the performance of the strategy was stunning.

  • Why is that?
  • What kind of market situations will it be flat (and losing)?
  • What kind of market situations will be winning?
  • If there are chances we can have signals telling us which market is favourable to the strategy? And telling us to or not to enter the market?
  • Can we decrease the volatility of the strategy, making it more stable across the course of time?

Overview: What's the win rate of the strategy?

In [14]:
df_trades['exit_Signal'].value_counts().sum()
Out[14]:
1350
  • Over 1000 trades are analysed here.
In [16]:
df_
Out[16]:
trades by exit type % of trades by exit type
Stop Loss 869 64.37
Sell 264 19.56
Cover 206 15.26
End of Day Exit 11 0.81
  • Overall, 64% of the trades had stopped-loss and only 35% of the trades were winning.

Were short entries more profitable than long entries? No.

In [19]:
ax = df_.plot.box(figsize=(7,4))
plt.ylabel('% of trades with stopped-loss in a month');
In [21]:
df_e
Out[21]:
Cover End of Day Exit Sell Stop Loss Total Trades % Cover % End of Day Exit % Sell % Stop Loss
entry_Type
Buy 0 6 264 463 733 0 1 36 63
Sell 206 5 0 406 617 33 1 0 66
  • The percentage of stopped-loss trades do not seem to differ much by whether the trades were long or short entries.
In [22]:
stats.ttest_ind(df_.Buy, df_.Sell)
Out[22]:
Ttest_indResult(statistic=-0.9417184689593945, pvalue=0.34957549118006104)
  • From t-test, there is no evidence that the long and short entries differ in % of trades with stopped-loss

Confirm Multichart results: Did the months in 2020-H2 made more profit?

In [24]:
df_monthly_profit.plot.bar( figsize=(12,5) ); 
  • YES. 2020 H2 had more profits compared to periods before and after; only 2020-10 had a loss.
  • 2021 Jan had the largest gain
  • 2019 Jul had the largest loss

Confirm Multichart results: Did 2020-H2 have less losing trades per month compared to other periods?

In [30]:
plt.style.use('bmh')
ax = df_.plot.box()
plt.ylabel('% of trades with stopped-loss in a month');
  • YES. 2020 H2 had a lower percentage of trades with stopped-loss in a month.

P.S. 2018 H1 only had 1 monthly data point.

In [31]:
df_exit_stat['% Stop Loss'].plot.bar( figsize=(12,5) );
  • The particularly low % of trades with stopped loss in 2020-H2 was not due to any outlier in a particular month, although 2020-Aug was lower in % of trades with stopped loss. So the outperformance of 2020-H2 was not a skewed result.

Investigate trades in 2019-July, which had many losses

  • Trades in 2019-Jul should indicate more strongly as to what caused the poor performance of the strategy.

Note: Entries are shown as triangles; stop-losses are crosses; short-cover and long-sell are pointers; end of day exits are pentagons

In [38]:
for i, trade in df_trades.query(str_201907).iterrows():
    plot_trade(trade, df_bar, my_style)
2019-07-02 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
449 Buy 2 28984 LE NaN 2019-07-02 09:46:00 LExit 2 28944 Stop Loss -4120 2019-07-02 10:13:00 13 loss

2019-07-02 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
450 Buy 2 28971 LEpm NaN 2019-07-02 13:46:00 LExit 2 28931 Stop Loss -4120 2019-07-02 15:59:00 7 loss

2019-07-03 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
451 Sell 2 28851 SE NaN 2019-07-03 09:46:00 SExit 2 28891 Stop Loss -4120 2019-07-03 10:07:00 65 loss

2019-07-03 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
452 Sell 2 28835 SEpm NaN 2019-07-03 13:46:00 SExit 2 28875 Stop Loss -4120 2019-07-03 15:00:00 1 loss

2019-07-04 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
453 Buy 2 29030 LE NaN 2019-07-04 09:46:00 LExit 2 28990 Stop Loss -4120 2019-07-04 09:51:00 5 loss

2019-07-04 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
454 Buy 2 28940 LEpm NaN 2019-07-04 13:46:00 LExit 2 28900 Stop Loss -4120 2019-07-04 14:19:00 20 loss

2019-07-05 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
455 Sell 2 28802 SE NaN 2019-07-05 09:46:00 SExit 2 28842 Stop Loss -4120 2019-07-05 09:47:00 14 loss

2019-07-05 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
456 Buy 2 28903 LEpm NaN 2019-07-05 13:46:00 LExit 2 28863 Stop Loss -4120 2019-07-05 14:26:00 14 loss

2019-07-08 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
457 Sell 2 28409 SE NaN 2019-07-08 09:46:00 SExit 2 28449 Stop Loss -4120 2019-07-08 09:52:00 70 loss

2019-07-08 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
458 Sell 2 28254 SEpm NaN 2019-07-08 13:46:00 SExit 2 28294 Stop Loss -4120 2019-07-08 14:29:00 7 loss

2019-07-09 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
459 Sell 2 28151 SEpm NaN 2019-07-09 13:46:00 SExit 2 28191 Stop Loss -4120 2019-07-09 13:57:00 19 loss

2019-07-10 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
460 Buy 2 28265 LE NaN 2019-07-10 09:46:00 LExit 2 28225 Stop Loss -4120 2019-07-10 09:53:00 36 loss

2019-07-10 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
461 Buy 2 28222 LEpm NaN 2019-07-10 13:46:00 LExit 2 28182 Stop Loss -4120 2019-07-10 14:35:00 28 loss

2019-07-11 09:46:00 # LE > Sell: 7080.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
462 Buy 2 28501 LE NaN 2019-07-11 09:46:00 LExit 2 28573 Sell 7080 2019-07-11 10:07:00 49 win

2019-07-11 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
463 Buy 2 28476 LEpm NaN 2019-07-11 13:46:00 LExit 2 28436 Stop Loss -4120 2019-07-11 14:00:00 37 loss

2019-07-12 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
464 Buy 2 28479 LE NaN 2019-07-12 09:46:00 LExit 2 28439 Stop Loss -4120 2019-07-12 09:47:00 22 loss

2019-07-12 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
465 Buy 2 28561 LEpm NaN 2019-07-12 13:46:00 LExit 2 28521 Stop Loss -4120 2019-07-12 14:34:00 3 loss

2019-07-15 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
466 Sell 2 28136 SE NaN 2019-07-15 09:46:00 SExit 2 28176 Stop Loss -4120 2019-07-15 09:53:00 84 loss

2019-07-15 13:46:00 # LEpm > Sell: 5080.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
467 Buy 2 28491 LEpm NaN 2019-07-15 13:46:00 LExit 2 28543 Sell 5080 2019-07-15 16:07:00 32 win

2019-07-16 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
468 Buy 2 28597 LE NaN 2019-07-16 09:46:00 LExit 2 28557 Stop Loss -4120 2019-07-16 09:47:00 5 loss

2019-07-16 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
469 Buy 2 28645 LEpm NaN 2019-07-16 13:46:00 LExit 2 28605 Stop Loss -4120 2019-07-16 15:01:00 16 loss

2019-07-17 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
470 Sell 2 28486 SE NaN 2019-07-17 09:46:00 SExit 2 28526 Stop Loss -4120 2019-07-17 09:48:00 105 loss

2019-07-17 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
471 Buy 2 28569 LEpm NaN 2019-07-17 13:46:00 LExit 2 28529 Stop Loss -4120 2019-07-17 14:12:00 12 loss

2019-07-18 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
472 Sell 2 28442 SE NaN 2019-07-18 09:46:00 SExit 2 28482 Stop Loss -4120 2019-07-18 10:40:00 10 loss

2019-07-18 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
473 Sell 2 28426 SEpm NaN 2019-07-18 13:46:00 SExit 2 28466 Stop Loss -4120 2019-07-18 14:21:00 21 loss

2019-07-19 09:46:00 # LE > Sell: 7180.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
474 Buy 2 28716 LE NaN 2019-07-19 09:46:00 LExit 2 28789 Sell 7180 2019-07-19 10:19:00 36 win

2019-07-19 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
475 Buy 2 28795 LEpm NaN 2019-07-19 13:46:00 LExit 2 28755 Stop Loss -4120 2019-07-19 17:54:00 3 loss

2019-07-22 13:46:00 # SEpm > Cover: 11880.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
476 Sell 2 28565 SEpm NaN 2019-07-22 13:46:00 SExit 2 28445 Cover 11880 2019-07-22 14:47:00 7 win

2019-07-23 09:46:00 # LE > Sell: 4280.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
477 Buy 2 28397 LE NaN 2019-07-23 09:46:00 LExit 2 28441 Sell 4280 2019-07-23 10:22:00 2 win

2019-07-23 13:46:00 # LEpm > Sell: 6280.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
478 Buy 2 28431 LEpm NaN 2019-07-23 13:46:00 LExit 2 28495 Sell 6280 2019-07-23 21:36:00 5 win

2019-07-24 09:46:00 # LE > Sell: 4280.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
479 Buy 2 28686 LE NaN 2019-07-24 09:46:00 LExit 2 28730 Sell 4280 2019-07-24 10:13:00 43 win

2019-07-24 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
480 Buy 2 28669 LEpm NaN 2019-07-24 13:46:00 LExit 2 28629 Stop Loss -4120 2019-07-24 14:14:00 8 loss

2019-07-25 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
481 Buy 2 28576 LE NaN 2019-07-25 09:46:00 LExit 2 28536 Stop Loss -4120 2019-07-25 10:00:00 64 loss

2019-07-25 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
482 Buy 2 28595 LEpm NaN 2019-07-25 13:46:00 LExit 2 28555 Stop Loss -4120 2019-07-25 21:25:00 1 loss

2019-07-26 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
483 Buy 2 28411 LE NaN 2019-07-26 09:46:00 LExit 2 28371 Stop Loss -4120 2019-07-26 09:48:00 9 loss

2019-07-26 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
484 Buy 2 28452 LEpm NaN 2019-07-26 13:46:00 LExit 2 28412 Stop Loss -4120 2019-07-26 15:15:00 5 loss

2019-07-29 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
485 Sell 2 28221 SE NaN 2019-07-29 09:46:00 SExit 2 28261 Stop Loss -4120 2019-07-29 09:47:00 34 loss

2019-07-29 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
486 Sell 2 27968 SEpm NaN 2019-07-29 13:46:00 SExit 2 28008 Stop Loss -4120 2019-07-29 15:13:00 31 loss

2019-07-30 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
487 Buy 2 28168 LE NaN 2019-07-30 09:46:00 LExit 2 28128 Stop Loss -4120 2019-07-30 09:52:00 2 loss

2019-07-30 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
488 Buy 2 28139 LEpm NaN 2019-07-30 13:46:00 LExit 2 28099 Stop Loss -4120 2019-07-30 17:16:00 7 loss

2019-07-31 09:46:00 # SE > Cover: 10380.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
489 Sell 2 27813 SE NaN 2019-07-31 09:46:00 SExit 2 27708 Cover 10380 2019-07-31 10:17:00 24 win

2019-07-31 13:46:00 # SEpm > End of Day Exit: -1520.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
490 Sell 2 27743 SEpm NaN 2019-07-31 13:46:00 SExit 2 27757 End of Day Exit -1520 2019-07-31 13:55:00 14 loss

Investigate trades in 2020-Aug, which had a good number of winning trades.

  • Trades in 2020-Aug should indicate more strongly as to what caused the better performance of the strategy.
In [39]:
for i, trade in df_trades.query(str_202008).iterrows():
    plot_trade(trade, df_bar, my_style)
2020-08-03 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
958 Sell 2 24450 SE NaN 2020-08-03 09:46:00 SExit 2 24490 Stop Loss -4120 2020-08-03 09:46:00 77 loss

2020-08-03 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
959 Sell 2 24345 SEpm NaN 2020-08-03 13:46:00 SExit 2 24385 Stop Loss -4120 2020-08-03 13:49:00 31 loss

2020-08-04 09:46:00 # LE > Sell: 5580.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
960 Buy 2 24552 LE NaN 2020-08-04 09:46:00 LExit 2 24609 Sell 5580 2020-08-04 10:18:00 78 win

2020-08-04 13:46:00 # LEpm > Sell: 33880.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
961 Buy 2 24625 LEpm NaN 2020-08-04 13:46:00 LExit 2 24965 Sell 33880 2020-08-04 13:53:00 21 win

2020-08-05 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
962 Buy 2 24962 LE NaN 2020-08-05 09:46:00 LExit 2 24922 Stop Loss -4120 2020-08-05 09:46:00 7 loss

2020-08-05 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
963 Buy 2 25031 LEpm NaN 2020-08-05 13:46:00 LExit 2 24991 Stop Loss -4120 2020-08-05 14:02:00 17 loss

2020-08-06 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
964 Sell 2 24686 SEpm NaN 2020-08-06 13:46:00 SExit 2 24726 Stop Loss -4120 2020-08-06 14:06:00 19 loss

2020-08-07 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
965 Sell 2 24732 SE NaN 2020-08-07 09:46:00 SExit 2 24772 Stop Loss -4120 2020-08-07 09:47:00 20 loss

2020-08-07 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
966 Sell 2 24479 SEpm NaN 2020-08-07 13:46:00 SExit 2 24519 Stop Loss -4120 2020-08-07 14:07:00 25 loss

2020-08-10 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
967 Buy 2 24368 LE NaN 2020-08-10 09:46:00 LExit 2 24328 Stop Loss -4120 2020-08-10 09:46:00 53 loss

2020-08-10 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
968 Buy 2 24458 LEpm NaN 2020-08-10 13:46:00 LExit 2 24418 Stop Loss -4120 2020-08-10 13:49:00 16 loss

2020-08-11 09:46:00 # LE > Sell: 8180.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
969 Buy 2 24780 LE NaN 2020-08-11 09:46:00 LExit 2 24863 Sell 8180 2020-08-11 09:55:00 75 win

2020-08-11 13:46:00 # LEpm > Sell: 5580.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
970 Buy 2 24932 LEpm NaN 2020-08-11 13:46:00 LExit 2 24989 Sell 5580 2020-08-11 14:06:00 36 win

2020-08-12 09:46:00 # SE > Cover: 5680.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
971 Sell 2 24752 SE NaN 2020-08-12 09:46:00 SExit 2 24694 Cover 5680 2020-08-12 09:54:00 1 win

2020-08-12 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
972 Sell 2 24812 SEpm NaN 2020-08-12 13:46:00 SExit 2 24852 Stop Loss -4120 2020-08-12 14:05:00 15 loss

2020-08-13 09:46:00 # SE > Cover: 4880.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
973 Sell 2 25303 SE NaN 2020-08-13 09:46:00 SExit 2 25253 Cover 4880 2020-08-13 09:57:00 17 win

2020-08-13 13:46:00 # SEpm > Cover: 4280.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
974 Sell 2 25212 SEpm NaN 2020-08-13 13:46:00 SExit 2 25168 Cover 4280 2020-08-13 14:27:00 11 win

2020-08-14 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
975 Buy 2 25172 LE NaN 2020-08-14 09:46:00 LExit 2 25132 Stop Loss -4120 2020-08-14 10:00:00 16 loss

2020-08-14 13:46:00 # LEpm > Sell: 4780.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
976 Buy 2 25200 LEpm NaN 2020-08-14 13:46:00 LExit 2 25249 Sell 4780 2020-08-14 14:00:00 5 win

2020-08-17 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
977 Buy 2 25293 LE NaN 2020-08-17 09:46:00 LExit 2 25253 Stop Loss -4120 2020-08-17 09:58:00 27 loss

2020-08-17 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
978 Buy 2 25498 LEpm NaN 2020-08-17 13:46:00 LExit 2 25458 Stop Loss -4120 2020-08-17 13:47:00 13 loss

2020-08-18 09:46:00 # SE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
979 Sell 2 25318 SE NaN 2020-08-18 09:46:00 SExit 2 25358 Stop Loss -4120 2020-08-18 09:50:00 27 loss

2020-08-18 13:46:00 # SEpm > Cover: 4780.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
980 Sell 2 25303 SEpm NaN 2020-08-18 13:46:00 SExit 2 25254 Cover 4780 2020-08-18 14:34:00 6 win

2020-08-19 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
981 Sell 2 25092 SEpm NaN 2020-08-19 13:46:00 SExit 2 25132 Stop Loss -4120 2020-08-19 13:52:00 27 loss

2020-08-20 09:46:00 # SE > Cover: 6580.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
982 Sell 2 24744 SE NaN 2020-08-20 09:46:00 SExit 2 24677 Cover 6580 2020-08-20 10:22:00 59 win

2020-08-20 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
983 Sell 2 24586 SEpm NaN 2020-08-20 13:46:00 SExit 2 24626 Stop Loss -4120 2020-08-20 13:49:00 41 loss

2020-08-21 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
984 Buy 2 24923 LE NaN 2020-08-21 09:46:00 LExit 2 24883 Stop Loss -4120 2020-08-21 09:49:00 30 loss

2020-08-21 13:46:00 # LEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
985 Buy 2 25074 LEpm NaN 2020-08-21 13:46:00 LExit 2 25034 Stop Loss -4120 2020-08-21 14:10:00 44 loss

2020-08-24 09:46:00 # LE > Sell: 6080.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
986 Buy 2 25427 LE NaN 2020-08-24 09:46:00 LExit 2 25489 Sell 6080 2020-08-24 10:01:00 81 win

2020-08-24 13:46:00 # LEpm > Sell: 5780.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
987 Buy 2 25480 LEpm NaN 2020-08-24 13:46:00 LExit 2 25539 Sell 5780 2020-08-24 20:29:00 6 win

2020-08-25 09:46:00 # LE > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
988 Buy 2 25527 LE NaN 2020-08-25 09:46:00 LExit 2 25487 Stop Loss -4120 2020-08-25 09:47:00 64 loss

2020-08-25 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
989 Sell 2 25432 SEpm NaN 2020-08-25 13:46:00 SExit 2 25472 Stop Loss -4120 2020-08-25 14:13:00 43 loss

2020-08-26 09:46:00 # LE > Sell: 5180.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
990 Buy 2 25509 LE NaN 2020-08-26 09:46:00 LExit 2 25562 Sell 5180 2020-08-26 09:55:00 44 win

2020-08-26 13:46:00 # SEpm > Stop Loss: -4120.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
991 Sell 2 25447 SEpm NaN 2020-08-26 13:46:00 SExit 2 25487 Stop Loss -4120 2020-08-26 23:43:00 7 loss

2020-08-27 09:46:00 # SE > Cover: 5080.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
992 Sell 2 25256 SE NaN 2020-08-27 09:46:00 SExit 2 25204 Cover 5080 2020-08-27 09:57:00 44 win

2020-08-27 13:46:00 # SEpm > Cover: 6380.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
993 Sell 2 25271 SEpm NaN 2020-08-27 13:46:00 SExit 2 25206 Cover 6380 2020-08-27 17:37:00 18 win

2020-08-28 09:46:00 # LE > Sell: 14680.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
994 Buy 2 25295 LE NaN 2020-08-28 09:46:00 LExit 2 25443 Sell 14680 2020-08-28 11:10:00 37 win

2020-08-28 13:46:00 # LEpm > Sell: 14080.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
995 Buy 2 25494 LEpm NaN 2020-08-28 13:46:00 LExit 2 25636 Sell 14080 2020-08-28 14:06:00 34 win

2020-08-31 09:46:00 # LE > Sell: 5280.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
996 Buy 2 25695 LE NaN 2020-08-31 09:46:00 LExit 2 25749 Sell 5280 2020-08-31 09:48:00 21 win

2020-08-31 13:46:00 # SEpm > Cover: 4780.0
entry_Type entry_Quantity entry_Price entry_Signal entry_Profit entry_Time exit_Type exit_Quantity exit_Price exit_Signal exit_Profit exit_Time pullback_at_entry win_loss
997 Sell 2 25527 SEpm NaN 2020-08-31 13:46:00 SExit 2 25478 Cover 4780 2020-08-31 14:08:00 35 win

  • From eyeballing the charts, seems like the winning trades happen more often when there were pullbacks in price and then the price continues in the direction of interest. Pullbacks seemed to happen more often in 2020-Aug and less in 2019-Jul.

Did winning trades happen more often when there were pullbacks ?

2019-Jul

In [40]:
ax = df_trades.query(str_201907)[ df_trades.query(str_201907)['pullback_at_entry'].notna() ].boxplot(by='win_loss', column=['pullback_at_entry'] )
ax.set_ylim(0,100);
In [42]:
stats.ttest_ind(s_win, s_loss)
Out[42]:
Ttest_indResult(statistic=0.15101457923787331, pvalue=0.8807232422476323)
  • 2019-Jul was a month with many loss trades and this month
  • And the winning trades tend to have more pullbacks (~28 pts); however, the difference in pullback between win and loss trades is not statistically significant.
In [43]:
df_trades.query(str_201907).groupby('win_loss')['pullback_at_entry'].describe()
Out[43]:
count mean std min 25% 50% 75% max
win_loss
loss 34.0 23.2941176 25.6745711 1.0 7.0 14.0 30.25 105.0
win 8.0 24.7500000 18.2189070 2.0 6.5 28.0 37.75 49.0

2020-Aug

In [44]:
ax = df_trades.query(str_202008)[ df_trades.query(str_202008)['pullback_at_entry'].notna() ].boxplot(by='win_loss', column=['pullback_at_entry'] )
ax.set_ylim(0,100);
In [46]:
stats.ttest_ind(s_win, s_loss)
Out[46]:
Ttest_indResult(statistic=0.521713512059104, pvalue=0.6048976342244508)
  • 2020-Aug was a month with many winning trades
  • And the winning trades tend to have more pullback (~34 pts); however, the difference in pullback between win and loss trades is not statistically significant.
In [47]:
df_trades.query(str_202008).groupby('win_loss')['pullback_at_entry'].describe()
Out[47]:
count mean std min 25% 50% 75% max
win_loss
loss 21.0 29.4761905 18.4136337 7.0 16.0 27.0 41.0 77.0
win 19.0 33.1052632 25.3418730 1.0 14.0 34.0 44.0 81.0
In [48]:
ax = df_trades[ df_trades['pullback_at_entry'].notna() ].boxplot(by='win_loss', column=['pullback_at_entry'] )
ax.set_ylim(0,100);
  • Indeed the difference in pullback between win and loss trades is not apparent at all when looking at all the trades from 2018 to 2021-H1.

Note: the boxplot is cropped at the top in order to see the median.

In [50]:
stats.ttest_ind(s_win, s_loss)
Out[50]:
Ttest_indResult(statistic=0.49609086468394875, pvalue=0.6199117229603801)

Does more volatile market bring more profit ?

In [59]:
ax = df_trades.query(str_b4_2020H2).boxplot(by='win_loss', column=['today_range'] ) 
ax.set_ylim(0,1000);
  • From 2018 to 2020-H1, the winning trades had higher volatility range and this result is statistically significant.
In [61]:
stats.ttest_ind(s_win, s_loss)
Out[61]:
Ttest_indResult(statistic=2.3151957484128523, pvalue=0.020822903723588537)
In [62]:
ax = df_trades.query(str_2020H2).boxplot(by='win_loss', column=['today_range'] ) 
ax.set_ylim(0,1000);
In [64]:
stats.ttest_ind(s_win, s_loss)
Out[64]:
Ttest_indResult(statistic=1.8744573615759983, pvalue=0.06210274555759647)
  • In 2020-H2, the winning trades had slightly higher volatility range; though this result is not statistically strong enough.
In [65]:
ax = df_trades.boxplot(by='win_loss', column=['today_range'] )
ax.set_ylim(0,1000);
In [67]:
stats.ttest_ind(s_win, s_loss)
Out[67]:
Ttest_indResult(statistic=3.4224379407301497, pvalue=0.0006392140918165176)
  • If volatility is high for the trading day then the strategy is more likely to win and this result is highly statistically significant

Should we place a trade in the afternoon if the volatility in the morning was high?

In [68]:
ax = df_trades.query('entry_Signal == "LEpm" | entry_Signal == "SEpm"').boxplot(by='win_loss', column=['morning_range'] )
ax.set_ylim(0,1000);
In [69]:
df_trades.query('entry_Signal == "LEpm" | entry_Signal == "SEpm"').groupby('win_loss')['morning_range'].describe()
Out[69]:
count mean std min 25% 50% 75% max
win_loss
loss 439.0 377.6059226 180.6913210 132.0 265.0 336.0 435.5 2059.0
win 248.0 383.3508065 167.6950973 104.0 273.5 340.0 459.0 1111.0
  • unfortunately, high volatility in the morning session does not lead to better winnings in the afternoon.
In [95]:
stats.ttest_ind(s_win, s_loss)
Out[95]:
Ttest_indResult(statistic=0.4106416065403708, pvalue=0.6814637667699426)

Does today's range correlate with previous day's range ?

In [72]:
df_trades[['today_range','prev_range']].corr()
Out[72]:
today_range prev_range
today_range 1.0000000 0.3866026
prev_range 0.3866026 1.0000000
  • There's only 38% correlation between today's volatility and previous day's volatility; not much at all.
In [73]:
df_trades[['today_range','prev_range']].plot.scatter(x='prev_range', y='today_range');
In [74]:
df_trades[['today_range','prev_range']].apply(lambda x: np.log(x)).add_prefix('log_').plot.scatter(x='log_prev_range', y='log_today_range');

Does today's win/loss correlate with previous day's range ?

In [76]:
plt.style.use('ggplot')
df_.plot.hist(bins=30,alpha=0.5, figsize=(12,5));
In [77]:
ax = df_trades.boxplot(by='win_loss', column=['prev_range'] )
ax.set_ylim(0,1000);
  • Unfortunately, previous day's range does not correlate with next day's win loss of the strategy.

Appendix

List of Trades with End of Day Exit

In [78]:
df_trade[ df_trade['Signal'] == 'End of Day Exit' ]
Out[78]:
Type Quantity Price Signal Profit Time
81 LExit 2 28644.0 End of Day Exit 880 2018-07-30 16:00:00
685 LExit 2 29659.0 End of Day Exit 8380 2019-04-02 01:00:00
745 LExit 2 29818.0 End of Day Exit -720 2019-04-29 16:00:00
883 LExit 2 28435.0 End of Day Exit 2380 2019-06-25 01:00:00
981 SExit 2 27757.0 End of Day Exit -1520 2019-07-31 13:55:00
1115 SExit 2 26730.0 End of Day Exit 5680 2019-09-19 01:00:00
1201 LExit 2 26857.0 End of Day Exit 5980 2019-10-23 01:00:00
1361 SExit 2 27850.0 End of Day Exit 4780 2019-12-24 01:00:00
1363 SExit 2 27880.0 End of Day Exit -2020 2019-12-24 12:30:00
1369 LExit 2 28348.0 End of Day Exit -520 2019-12-30 16:00:00
1827 SExit 2 24302.0 End of Day Exit -220 2020-06-29 16:00:00